$console = $$module('jDev.console', {

  log: function(){
    $console.logFormatted(arguments, '');
  },
  
  debug: function(){
    $console.logFormatted(arguments, 'debug');
  },
  
  info: function(){
    $console.logFormatted(arguments, 'info');
  },
  
  warn: function(){
    $console.logFormatted(arguments, 'warning');
  },
  
  error: function(){
    $console.logFormatted(arguments, 'error');
  },
  
  assert: function(truth, message){
    if (!truth) {
      var a = Array.prototype.slice.call(arguments, 1);
      
      $console.logFormatted(a.length ? a : ['Assertion Failure'], 'error');
      throw message ? message : 'Assertion Failure';
    }
  },
  
  dir: function(object){
    var html = [];
                
    var pairs = [];
    for (var name in object){
      try{
        pairs.push([name, object[name]]);
      }catch (exc){}
    }
    
    pairs.sort(function(a, b) { return a[0] < b[0] ? -1 : 1; });
    
    html.push('<table>');
    for (var i = 0; i < pairs.length; ++i){
      var name = pairs[i][0], value = pairs[i][1];
      
      html.push('<tr>', 
          '<td class="propertyNameCell"><span class="propertyName">',
          escapeHTML(name), 
          '</span></td><td><span class="propertyValue">'
        );

      appendObject(value, html);
      html.push('</span></td></tr>');
    }
    html.push('</table>');
    
    logRow(html, 'dir');
  },
  
  dirxml: function(node){
    var html = [];
    
    appendNode(node, html);
    logRow(html, 'dirxml');
  },
  
  group: function(){
    logRow(arguments, 'group', pushGroup);
  },
  
  groupEnd: function(){
    logRow(arguments, '', popGroup);
  },
  
  time: function(name){
    timeMap[name] = (new Date()).getTime();
  },
  
  timeEnd: function(name){
    if (name in timeMap){
      var delta = (new Date()).getTime() - timeMap[name];
      $console.logFormatted([name+ ':', delta+'ms']);
      delete timeMap[name];
    }
  },
  
  count: function(){
    this.warn(['count() not supported.']);
  },
  
  trace: function(){
    this.warn(['trace() not supported.']);
  },
  
  profile: function(){
    this.warn(['profile() not supported.']);
  },
  
  profileEnd: function(){
    this.warn(['profile() not supported.']);
  },
  
  clear: function(){
    consoleBody.innerHTML = '';
  }
  
});
